/*******************************************************************************
 *
 * Copyright (c) 2008-2011 ayound@gmail.com
 * This program and the accompanying materials
 * are made available under the terms of the GNU GENERAL PUBLIC LICENSE
 * which accompanies this distribution, and is available at
 * http://dev.perl.org/licenses/gpl1.html
 * All rights reserved.
 *
 * Created on 2009-11-10
 *******************************************************************************/

package org.ayound.skin.editor.core;

import java.awt.Color;
import java.awt.image.RGBImageFilter;

/**
 * ColorMaskFilter. <br>
 *
 */
public class ColorMaskFilter extends RGBImageFilter implements IColorConvert {

	Color color;

	public ColorMaskFilter(Color mask) {
		color = mask;
		canFilterIndexColorModel = true;
	}

	public int filterRGB(int x, int y, int pixel) {
		return 255 << 24
				| (((pixel & 0xff0000) >> 16) * color.getRed() / 255) << 16
				| (((pixel & 0xff00) >> 8) * color.getGreen() / 255) << 8
				| (pixel & 0xff) * color.getBlue() / 255;
	}

	public Color convert(Color color) {
		return new Color(filterRGB(0, 0, color.getRGB()));
	}

}
